package com.huanying.goodjob.appraise;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huanying.framework.BaseDao;
import com.huanying.framework.user.User;



@Service
public class AppraiseServiceImpl implements AppraiseService {

	@Autowired
	private BaseDao dao;

	@Override
	public void add(Appraise appraise) throws Exception {
		// TODO Auto-generated method stub
		dao.save(appraise);
	}

	@Override
	public void update(Appraise appraise) throws Exception {
		// TODO Auto-generated method stub
		dao.update(appraise);
		
	}
	@Override
	public void updateLabel(Label label) throws Exception {
		// TODO Auto-generated method stub
		dao.update(label);
		
	}

	@Override
	public void delete(int id) throws Exception {
		// TODO Auto-generated method stub
		List<Object> param = new ArrayList<Object>();
		String hql = "update Appraise set status=0 where id=?";
		param.add(id);
		dao.exculeByParams(hql, param);
	}

	@Override
	public Appraise getbyId(int id) throws Exception {
		// TODO Auto-generated method stub
		return (Appraise) dao.load(Appraise.class, id);
	}

	@Override
	public List search_appraise(int user_id) throws Exception {
		// TODO Auto-generated method stub
		String hql="from Appraise where status=1 and appraiseobject.id=?";
		List<Object> param = new ArrayList<Object>();
		param.add(user_id);
		return dao.exculeHqlByParams(hql, param);
	}

	//获得的评分
	public List<Appraise> getAppraise(int id)throws Exception{
		String hql = "from Appraise as a where a.status=1 and a.appraiseobject.id=?";
		List<Object> params = new ArrayList<Object>();
		params.add(id);
	   return dao.exculeHqlByParams(hql, params);
		
	}
	@Override
	public Label getbyId_Label(int id) throws Exception {
		// TODO Auto-generated method stub
		return (Label) dao.load(Label.class, id);
	}
	//工人身份
	public List<Label> getLabel_worker(int authentic_status,int jobtype_id)throws Exception{
		String hql = "from Label as l where l.status=1 and l.authentic_status=? and l.jobtype_id=?";
		List<Object> params = new ArrayList<Object>();
		params.add(authentic_status);
		params.add(jobtype_id);
	   return dao.exculeHqlByParams(hql, params);	
	}
	//工长身份
	public List<Label> getLabel_boss(int authentic_status)throws Exception{
		String hql = "from Label as l where l.status=1 and l.jobtype_id=0 and l.authentic_status=?";
		List<Object> params = new ArrayList<Object>();
		params.add(authentic_status);
	   return dao.exculeHqlByParams(hql, params);	
	}
	/*for (int i = 0; i < menuid_array.length; i++) {
		role_menu.setMenu_id(Integer.valueOf(menuid_array[i]));
		dao.save(role_menu);
	}*/
	//通过一组label_id获得
	public List<Label> getLabelById(String[] label_id_array)throws Exception{
		List<Label> list = new ArrayList<Label>();
		for(int i = 0; i < label_id_array.length; i++) {
			//list.add((Label) dao.load(Label.class, Integer.valueOf(label_id_array[i])));
			Label label=new Label();
			String hql = new String("from Label l where l.status=1 and l.id=?");
			List<Object> params = new ArrayList<Object>();
			params.add(Integer.valueOf(label_id_array[i]));
			label=(Label) dao.exculeHqlGetOjbectByParams(hql, params);
			list.add(label);
		}
		return list;
	}
}
